/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.web.servlet;

import com.web.entity.Test;
import com.web.service.Testdaoimpl;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author liqianru
 */
@WebServlet("/add")
public class Addtest extends HttpServlet {

    Testdaoimpl service = new Testdaoimpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取请求参数
        String cid = req.getParameter("cid");
        String answer = req.getParameter("answer");
        String topic = req.getParameter("topic");
        String questionA = req.getParameter("A");
        String questionB = req.getParameter("B");
        String questionC = req.getParameter("C");
        String questionD = req.getParameter("D");
        int score = Integer.valueOf(req.getParameter("score"));
        int qid = Integer.valueOf(req.getParameter("qid"));
        int courseid = Integer.valueOf(req.getParameter("courseid"));
        int rows=0;
        Test test = new Test(topic, questionA, questionB, questionC, questionD, answer, score,"isnull", qid,courseid, cid);
        if (req.getParameter("action").equals("add")) {
            rows = service.insertTest(test);
            System.out.println("成功" + cid + score + questionA + "--" + rows);
        }
        if(req.getParameter("action").equals("modify")){
            rows=service.modifyTest(test);
            System.out.println("修改成功"+rows);
            resp.getWriter().print(rows);
        }
    }

}
